In this lecture, we're going to take a quick look at proximity prompts, which are basically billboard
guy buttons that you can interact with to trigger an event in the prompt.
Proximity prompts only appear on the screen once a player gets close enough to one, based on one of
its properties, called Max activation distance.
We can place proximity prompts inside of parts, and the prompt will appear at the origin of a particular
part.
Or, if we would like to be able to change the positioning of a proximity prompt within a part, then
we can also use attachments and the prompt will appear at the position of the attachment.
So I can add a proximity prompt to this part.
And for demonstration purposes I'm also going to add one over here inside of this attachment.
And then I'm going to add another proximity prompt inside of this part.
And for this one I'm going to keep requires line of sight enabled.
And then for the other ones I'm going to disable that property.
And this property basically determines whether or not we can see the proximity prompt appear through
walls.
And as you can see when I play test the Game, here's our first proximity prompt that is inside of the
center of this part.
My other proximity prompt is right over here inside of the attachment, and then my other proximity
prompt is over here inside of this part.
Now I'm not able to see that other one over on this other side of the part.
And that's because the max activation distance is not large enough.
So let me go ahead and select it and increase its max activation distance to let's say 30 studs.
So now we should be able to or actually okay.
Yeah.
This is the one that requires line of sight.
My bad I have that one mistaken.
So once I can no longer see the part because it's blocking my view with this other part, as you can
see, it disappears.
It isn't until I regain sight that it will reappear.
And then for these other prompts inside of this part, let me go ahead and increase the max activation
distance.
Even if I'm behind this other part here, I'm still able to see those other proximity prompts.
So let's go ahead and take a look at the different properties inside of a proximity prompt.
One would be the action text, and this is going to be the text that appears inside of the proximity
prompt, basically telling them what the action is or what's going to happen when they trigger this
prompt.
By default, it's just set to a string of interact.
But you can place any text inside of here that you want.
For example, you can change the action text to maybe um, trigger bomb or something like that if it's
a bomb.
The next property here is called clickable prompt, and this just determines whether or not a player
on PC is able to use their mouse button to hold down and interact with the proximity prompt.
If you disable this, then the only way for the player to interact or trigger the proximity prompt would
have to be using the Keycode.
That's determined by the keyboard Keycode property, so they have to hold down E on their keyboard.
The enable property is very self-explanatory.
If you disable it, the proximity prompt will disappear and it will no longer work.
But if you re-enable it, then it will display back on the screen.
If the player is close enough with it and the player can interact with it.
This property, called exclusivity, is specifically for determining how proximity prompts will display.
So for example, if you set it to one per button, what is going to happen is that only one prompt will
appear on the player's screen based on the keycode.
So if you had a proximity prompt with a keycode of E and another one with the keycode of Q, both of
them would appear on the screen if both were set to the one per button enum.
But if, let's say both had the keyboard keycode of E, then only one of them is going to show at a
time.
If you set it to one globally, then it will only display one proximity prompt at a time, no matter
what.
And then the last one is going to be always show, which allows the proximity prompt to appear on the
screen.
No matter if there is other proximity prompts around it, it will always show on the screen once the
player gets close enough to it.
We have the ability to change what Keycode needs to be pressed down on a gamepad or a controller.
For console players, we can determine the whole duration.
So how long do you have to hold it to trigger the prompt?
We can change the keyboard keycode to a whole bunch of other different keys.
I believe the default is always going to be E.
We can change how far away the player can interact with the proximity prompt.
With the max activation distance, we can set something called the object text inside of the proximity
prompt, which is just another little extra description that you can give it.
For this one, I'll just give it a example.
Object text string.
We are able to change this property requires a line of sight, which I explained earlier.
Basically, if you can see the proximity prompt through other parts, or if it should disappear when
you can no longer see it.
The style enum basically allows you just to change it from default to custom, and then you can check
this style property, check to see if it's custom, and then you would write your own script to display
a custom proximity prompt.
So this is for if you don't like Roblox's default implementation with proximity prompts and you want
to make your own custom UI, you would set the style to custom, which would disable the default behavior
for the proximity prompt, or it won't show the default UI.
And then that's where you can script your own GUI or UI for the proximity prompt.
And then UI offset is for offsetting the prompts UI in pixels on the x and the y axes.
So let's go ahead and set the whole duration to let's say three seconds.
Let's change the keyboard key code to.
Let's say let's do C, we'll keep the max activation distance at ten.
We'll have this object text, this action text.
And then we have clickable prompt disabled.
So I'll actually show you what that does.
Let me play test the game.
And then I can go over here.
There is my action text trigger bomb.
And then there's my object text.
So example object text I have to press C on my keyboard.
And if I click with my mouse button I'm unable to interact with this proximity prompt.
However, with this other one, I am able to click on it to interact with the proximity prompt.
For this one I have to hold down C, and there it fills in for a total of three seconds and then it
triggers the prompt, but I'm not able to click on it.
Now there are several events we can listen to inside of our proximity prompts.
So I'm just inside of a local script and I'm going to make a reference to my prompt, which is in the
workspace.
I'll get my part.
Let me rename it to Proximity Part.
So I'll get my proximity part, and then I'll refer to the attachment and I'll just grab the proximity
prompt in that one.
And then let me make sure that streaming is disabled so I don't have to use wait for child.
And now inside of my prompt I have access to several events which are listed right here.
For example, we can listen for when the prompt is triggered.
So it says triggered when the prompt key button is pressed, or after a specified amount of time.
Um, for holding the button we have some other events such as prompt button hold began and says triggered
when a player begins holding down connected to a prompt with a non-zero hold duration.
So this is specifically for any proximity prompts whose hold duration is greater than zero.
And then we also have one.
Actually let me type out prompt.
We have one for when the hold begins.
We have one for when the hold ends.
And then we have two other events here.
And this is specifically for the client.
So this will tell us when the prompt has been displayed on the screen on the client, and when the prompt
has become hidden on the client.
These are client only events.
You can't use these on the server.
So let's go ahead and listen to all of these events.
I'll just connect a function to each one of them.
It'll also tell us the player who triggered or who is holding down the current button.
So we'll just print out their name.
Let me make a parameter for that player, and then we'll just print out the player's name.
We'll do the same thing for when the hold ends.
So hold and we'll print player name.
And actually let's go ahead and insert an extra string.
So we'll call this one start.
Concatenate it with the player name and then we'll just copy that.
Do the same thing here but we'll say end.
We'll also listen for when the prompt is triggered.
It'll also tell us what player triggered the prompt.
So we'll just print out triggered.
And it was triggered by this player.
We'll get their name and then we can go ahead and also listen for when the prompt is displayed on the
screen.
So prompt shown.
We'll just print shown.
And then last but not least, we'll listen.
For when the prompt becomes hidden, we'll connect a function to that and print out.
Hidden.
Okay, let's go ahead and play test the game.
If I go and walk over to this prompts, there we go.
We get printed out, shown, and then if I walk away, it becomes hidden.
Then it's shown again.
If I hold down, we should see hold begin.
So we'll hold down.
See?
There we go.
It started and then my name printed out.
And then we ended the hold because it got triggered.
So it printed end and it also printed triggered.
Now one issue you might see with this is let's say you have dozens or hundreds of proximity prompts
and your game, you don't want to have to make a references to every single one of those proximity prompts
to be able to listen for maybe when it's shown or it's hidden or when it's triggered and whatnot.
So Roblox has provided a service for us called the Proximity Prompt Service.
So we'll call this Proximity prompt service is equal to game jet service, proximity Prompt service.
And this service has a ton of useful events that are very similar to the events that are inside of a
proximity prompt.
However, these events will fire any time a prompt is triggered or displayed or held down in your game.
So we have different events.
For example, prompt Buttonholed began triggers when the player begins holding down a proximity prompt,
and if we connect to this event, it'll give us what prompt is being held down and the player that triggered
it.
We can do the same thing for when a prompt ends, and it'll give us the proximity prompt and the player
we can listen for when a prompt is triggered.
And again, it'll give us that prompt and the player.
And then specifically for the client side, we can listen for when any prompt in our game is shown,
or when any of the prompts in our game are hidden.
And then we're also able to listen for when the trigger ends on a proximity prompt.
And I believe we can do that for regular.
Yeah, we could do that for regular proximity prompts as well.
So it says triggers when the key button is released for longer events when the user is required to hold
down the button.
So if you remember earlier with my proximity prompt that appears right here, I have to hold it down.
And then if I keep holding it down, it's going to keep the button triggered.
It isn't until I release my finger off of that key where the trigger ended event will fire.
The proximity prompts are very useful to use in your games.
Most of the time, you're just going to be using them to listen for when a player interacts with a specific
thing in your game.
Of course, you can create more customized proximity prompts by creating a custom GUI, but that's a
little bit more advanced than what we're going to focus on with this video.
Other than that, that was just my brief overview of proximity prompts.
That's all for me in this lecture.
I hope you enjoyed and I'll see you in the next one.